import 'package:flutter/material.dart';

// void main() {
//   runApp(const MyApp());
// }
//
// class MyApp extends StatelessWidget {
//   const MyApp({super.key});
//
//   @override
//   Widget build(BuildContext context) {
//     return const MaterialApp(
//       title: 'UnconstrainedBox Demo',
//       home: UnconstrainedBoxPage(),
//     );
//   }
// }

class UnconstrainedBoxPage extends StatelessWidget {
  const UnconstrainedBoxPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('UnconstrainedBox 学习案例')),
      body: Column(
        children: [
          const Text("没有 UnconstrainedBox（会被拉伸）"),
          Row(
            children: [
              Expanded(
                child: Container(
                  height: 80,
                  width: 100,
                  color: Colors.red,
                  child: const Center(
                      child:
                          Text("被拉伸", style: TextStyle(color: Colors.white))),
                ),
              ),
            ],
          ),
          const SizedBox(height: 30),
          const Text("使用 UnconstrainedBox（保持自身大小）"),
          Row(
            children: [
              Expanded(
                // UnconstrainedBox 会移除父布局对子元素的 最大/最小约束。
                child: UnconstrainedBox(
                  child: Container(
                    // width: 100,
                    height: 80,
                    color: Colors.blue,
                    child: const Center(
                        child: Text("保持大小",
                            style: TextStyle(color: Colors.white))),
                  ),
                ),
              ),
            ],
          ),
          ConstrainedBox(
            constraints: const BoxConstraints(
              minWidth: 100,
              minHeight: 100,
              maxWidth: 200,
              maxHeight: 200,
            ),
            child: Container(
              width: 50,
              height: 50,
              color: Colors.red,
              child:Center(child: Text("constrainedBox"))
            ),
          )
        ],
      ),
    );
  }
}
